<template>
  <div>
    <el-container class="indexPage">
      <el-aside width="200px">
        <h2>黑马头条</h2>
        <div>
          <h4 style="line-height: 60px; margin-right: 60px; color: #333333">
            文章管理
          </h4>
          <el-menu text-color="#888" active-text-color="red">
            <el-menu-item
              index="2"
              @click="$router.push('postlist').catch((err) => {})"
            >
              <!-- <i class="el-icon-menu"></i> -->
              <span slot="title">文章列表</span>
            </el-menu-item>
            <el-menu-item
              index="3"
              @click="$router.push('editpost').catch((err) => {})"
            >
              <!-- <i class="el-icon-document"></i> -->
              <span slot="title">发布文章</span>
            </el-menu-item>
          </el-menu>
        </div>
      </el-aside>
      <el-container>
        <el-header>
          <div class="info">
            <div class="avatar">
              <img
                v-if="userInfo.head_img"
                :src="$axios.defaults.baseURL + userInfo.head_img"
                alt=""
              />
            </div>
            <div class="name">{{ userInfo.nickname }}</div>
            <div class="back" @click="$router.push('/login')">退出</div>
          </div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userInfo: {},
    };
  },
  created() {
    // console.log(localStorage.getItem("token"));
    // console.log(localStorage.getItem("userId"));
    //发送请求获取数据
    this.$axios({
      url: "/user/" + localStorage.getItem("userId"),
      headers: {
        Authorization: "Bearer " + localStorage.getItem("token"),
      },
    }).then((res) => {
      // console.log(res);
      // 获取成功将用户数据存放到当前的 data 当中
      if (res.data.message == "获取成功") {
        this.userInfo = res.data.data;
        console.log(this.userInfo);
      }
    });
  },
};
</script>

<style lang="less" scoped>
.indexPage {
  height: 100vh;
}
.el-header,
.el-footer {
  background-color: #333333;
  color: #ccccca;
  text-align: right;
  line-height: 60px;
  .info {
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    .avatar {
      width: 40px;
      height: 40px;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }
    }
    .name {
      margin: 0 10px;
    }
  }
}

.el-aside {
  background-color: palevioletred;
  color: #ccccca;
  text-align: center;
  line-height: 80px;
}

.el-main {
  // background-color: papayawhip;
  color: #333;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>